package com.example.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.pojo.Quexianzhiding;
import com.example.service.QuexianService;

@RestController
@RequestMapping("qz")
public class QuexianzhidingController {
	@Autowired
	 QuexianService service;
	//分页查询
	@RequestMapping("findall/{page}/{size}")
	public Page<Quexianzhiding> findAll(@PathVariable("page") Integer page,@PathVariable("size") Integer size) {
   	 Pageable pageable=PageRequest.of(page-1, size);
   	 System.out.println("aoligei");
	  return service.findAll(pageable);
		
	}
	
	//根据id查询
	@GetMapping("findbyid/{id}")
	 public Quexianzhiding findbyid(@PathVariable("id") Integer id) {
		return service.findByid(id).get();
	  }
	
	//新增
	@RequestMapping("/insert")
	public String insert(@RequestBody Quexianzhiding q) {
		Quexianzhiding qw=service.insert(q);
		if(qw!=null){
			return "success";
		}else {
			return "error";
		}
	}
		//修改
	@RequestMapping("/update")
    public String update(@RequestBody Quexianzhiding q) {
		Quexianzhiding qq=service.update(q);
         if(qq!=null) {
        	 return "success";
         }else {
        	 return "error";
         }
		
	}
	//mybatis
	@RequestMapping("/updateisqx")
	public void updateisqx(Integer rwid,String isqx) {
		service.updateisqx(rwid, isqx);
	}
	     //多条件查询
	    @RequestMapping("/mohufind")
		public List<Quexianzhiding> mohufind(Integer rwid,String rwname,String rwdj,String xfuser,String xfdate) {
			System.out.println(service.mohufind(rwid, rwname, rwdj, xfuser, xfdate));
	    	return service.mohufind(rwid, rwname, rwdj, xfuser, xfdate);
		}
		//倒序查询所有
	    @RequestMapping("/findallque")
		public List<Quexianzhiding> findallque(){
	    
	    	return service.findallque();
			
		}
      
	  //模糊查询下发人倒序出来
	    @RequestMapping("/mhcxque")
		public List<Quexianzhiding> mhcxque(String rwname,String xfuser){
	    	return service.mhcxque(rwname,xfuser);
		}
}
